package Experiment1;

/**
 * Created by zhangyunqi on 2017/9/26.
 */
import java.util.ArrayList;
import java.util.List;


public class MergeList {
    private static List list = new ArrayList();
    public static List<? extends Comparable> mergeSortedList(List<? extends Comparable> aList,
                                                             List<? extends Comparable> bList){
        if(aList.isEmpty() && bList.isEmpty())
        {
            return list;
        }else if(!aList.isEmpty() && bList.isEmpty())
        {
            list.addAll(aList);
        }else if(aList.isEmpty() && !bList.isEmpty())
        {
            list.addAll(bList);
        }else if(aList.get(0).compareTo(bList.get(0))==0)
        {
            list.add(aList.remove(0));
            list.add(bList.remove(0));
            mergeSortedList(aList,bList);
        }else if(aList.get(0).compareTo(bList.get(0))>0)
        {
            list.add(bList.remove(0));
            mergeSortedList(aList,bList);
        }else if(aList.get(0).compareTo(bList.get(0))<0)
        {
            list.add(aList.remove(0));
            mergeSortedList(aList,bList);
        }
        return list;
    }
}
